package com.GZHU.controller.query_info;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Controller
public class Query_verify_info {
    @Autowired
    JdbcTemplate jdbcTemplate;
    @GetMapping("/query_verify_info")
    public String query_model_info(@RequestParam(value = "model_id") String model_id, HttpServletRequest request){
        HashMap<String,String> res=new HashMap<String,String>();
        // 查询语句
        String sql="select * from verify_info where model_id="+model_id;
        List res0=jdbcTemplate.queryForList(sql);

        if (res0.size()==0){
            log.info("数据查询结果为空");
        }
        else {
            Map a=(Map) res0.get(0);
            ArrayList<String> val=new ArrayList<String>();
            ArrayList<String> key=new ArrayList<String>();
            for (Object i0:
                    a.values()) {
                val.add(i0.toString());
            }
            for (Object i1:
                    a.keySet()) {
                key.add(i1.toString());
            }
            for (int i = 0; i <val.size() ; i++) {
                res.put(key.get(i),val.get(i));
            }
            request.setAttribute("model_id",res.get("model_id"));
            request.setAttribute("verify_id",res.get("verify_id"));
            request.setAttribute("verifyer_id",res.get("verifyer_id"));
            request.setAttribute("note",res.get("note"));
            request.setAttribute("is_original",res.get("is_original"));
            request.setAttribute("is_complete",res.get("is_complete"));
            request.setAttribute("is_pass",res.get("is_pass"));
        }
        return "verify_info";
    }
}
